/*
* Copyright 2025 NXP
* NXP Proprietary. This software is owned or controlled by NXP and may only be used strictly in
* accordance with the applicable license terms. By expressly accepting such terms or by downloading, installing,
* activating and/or otherwise using the software, you are agreeing that you have read, and that you agree to
* comply with and are bound by, such license terms.  If you do not agree to be bound by the applicable license
* terms, then you may not retain, install, activate or otherwise use the software.
*/

#include "lvgl.h"
#include <stdio.h>
#include "gui_guider.h"
#include "events_init.h"
#include "widgets_init.h"
#include "nrf_process.h"
#include "custom.h"

static void mask_event_cb(lv_event_t *e)
{
    #if 0
    lv_obj_t *roller = lv_event_get_target(e);
    lv_event_code_t code = lv_event_get_code(e);
    // 获取当前被选中的索引（第几项，从 0 开始）
    uint16_t sel_id = lv_roller_get_selected(roller);
    switch (code) {
        case LV_EVENT_PRESSED:
        {
            nrf_para.nrf.start_send_flag = true;
            // 设置按下时的样式

            lv_obj_set_style_bg_color(roller, lv_color_hex(guider_ui.color.backlight), LV_PART_SELECTED);
            lv_obj_set_style_text_color(roller, lv_color_hex(0x2195f6), LV_PART_SELECTED);
            if(sel_id == 0) {
                nrf_para.nrf.send_cmd = MASSAGE_MODE1_CMD;
            } else if (sel_id == 1) {
                nrf_para.nrf.send_cmd = MASSAGE_MODE2_CMD;
            } else if (sel_id == 2) {
                nrf_para.nrf.send_cmd = MASSAGE_MODE3_CMD;
            } else if (sel_id == 3) {
                nrf_para.nrf.send_cmd = MASSAGE_MODE4_CMD;
            }
            break;
        }
        case LV_EVENT_RELEASED:
        {
            lv_obj_set_style_bg_color(roller, lv_color_hex(guider_ui.color.backlight), LV_PART_SELECTED);
            lv_obj_set_style_text_color(roller, lv_color_hex(0xffffff), LV_PART_SELECTED);
            break;
        }
        default:
            break;
    }
    #endif
}

void setup_scr_massage_mode(lv_ui *ui)
{
    //Write codes massage_mode
    ui->massage_mode = lv_obj_create(NULL);
    lv_obj_set_size(ui->massage_mode, 240, 320);
    lv_obj_set_scrollbar_mode(ui->massage_mode, LV_SCROLLBAR_MODE_OFF);

    //Write style for massage_mode, Part: LV_PART_MAIN, State: LV_STATE_DEFAULT.
    lv_obj_set_style_bg_opa(ui->massage_mode, 255, LV_PART_MAIN|LV_STATE_DEFAULT);
    lv_obj_set_style_bg_color(ui->massage_mode, lv_color_hex(guider_ui.color.backlight), LV_PART_MAIN|LV_STATE_DEFAULT);
    lv_obj_set_style_bg_grad_dir(ui->massage_mode, LV_GRAD_DIR_NONE, LV_PART_MAIN|LV_STATE_DEFAULT);

    //Write codes massage_mode_roller_1
    ui->massage_mode_roller_1 = lv_roller_create(ui->massage_mode);
    lv_roller_set_options(ui->massage_mode_roller_1, "MODE 1\nMODE 2\nMODE 3\nMODE 4", LV_ROLLER_MODE_INFINITE);
    lv_obj_set_pos(ui->massage_mode_roller_1, 0, 119);
    lv_obj_set_width(ui->massage_mode_roller_1, 240);

    //Write style for massage_mode_roller_1, Part: LV_PART_MAIN, State: LV_STATE_DEFAULT.
    lv_obj_set_style_radius(ui->massage_mode_roller_1, 5, LV_PART_MAIN|LV_STATE_DEFAULT);
    lv_obj_set_style_bg_opa(ui->massage_mode_roller_1, 255, LV_PART_MAIN|LV_STATE_DEFAULT);
    lv_obj_set_style_bg_color(ui->massage_mode_roller_1, lv_color_hex(guider_ui.color.backlight), LV_PART_MAIN|LV_STATE_DEFAULT);
    lv_obj_set_style_bg_grad_dir(ui->massage_mode_roller_1, LV_GRAD_DIR_NONE, LV_PART_MAIN|LV_STATE_DEFAULT);
    lv_obj_set_style_text_color(ui->massage_mode_roller_1, lv_color_hex(0xffffff), LV_PART_MAIN|LV_STATE_DEFAULT);
    lv_obj_set_style_text_font(ui->massage_mode_roller_1, &lv_font_montserrat_14, LV_PART_MAIN|LV_STATE_DEFAULT);
    lv_obj_set_style_text_opa(ui->massage_mode_roller_1, 255, LV_PART_MAIN|LV_STATE_DEFAULT);
    lv_obj_set_style_text_align(ui->massage_mode_roller_1, LV_TEXT_ALIGN_CENTER, LV_PART_MAIN|LV_STATE_DEFAULT);
    lv_obj_set_style_border_width(ui->massage_mode_roller_1, 0, LV_PART_MAIN|LV_STATE_DEFAULT);
    lv_obj_set_style_shadow_width(ui->massage_mode_roller_1, 0, LV_PART_MAIN|LV_STATE_DEFAULT);

    //Write style for massage_mode_roller_1, Part: LV_PART_SELECTED, State: LV_STATE_DEFAULT.
    lv_obj_set_style_bg_opa(ui->massage_mode_roller_1, 255, LV_PART_SELECTED|LV_STATE_DEFAULT);
    lv_obj_set_style_bg_color(ui->massage_mode_roller_1, lv_color_hex(guider_ui.color.backlight), LV_PART_SELECTED|LV_STATE_DEFAULT);
    lv_obj_set_style_bg_grad_dir(ui->massage_mode_roller_1, LV_GRAD_DIR_NONE, LV_PART_SELECTED|LV_STATE_DEFAULT);
    lv_obj_set_style_text_color(ui->massage_mode_roller_1, lv_color_hex(0x2195f6), LV_PART_SELECTED|LV_STATE_DEFAULT);
    lv_obj_set_style_text_font(ui->massage_mode_roller_1, &lv_font_montserrat_18, LV_PART_SELECTED|LV_STATE_DEFAULT);
    lv_obj_set_style_text_opa(ui->massage_mode_roller_1, 255, LV_PART_SELECTED|LV_STATE_DEFAULT);
    lv_obj_set_style_text_align(ui->massage_mode_roller_1, LV_TEXT_ALIGN_CENTER, LV_PART_SELECTED|LV_STATE_DEFAULT);

    lv_roller_set_visible_row_count(ui->massage_mode_roller_1, 3);
    if (backlight.bits.msg_mode1) {
        lv_roller_set_selected(ui->massage_mode_roller_1, 0, LV_ANIM_ON);
    } else if (backlight.bits.msg_mode2) {
        lv_roller_set_selected(ui->massage_mode_roller_1, 1, LV_ANIM_ON);
    } else if (backlight.bits.msg_mode3) {
        lv_roller_set_selected(ui->massage_mode_roller_1, 2, LV_ANIM_ON);
    } else if (backlight.bits.msg_mode4) {
        lv_roller_set_selected(ui->massage_mode_roller_1, 3, LV_ANIM_ON);
    }



    // 创建并设置 group
    lv_group_t *main_group = lv_group_create();
    lv_group_add_obj(main_group, ui->massage_mode_roller_1);
    lv_indev_set_group(indev_keypad, main_group);



    lv_obj_add_event_cb(ui->massage_mode_roller_1, mask_event_cb, LV_EVENT_ALL, NULL);

    //Update current screen layout.
    lv_obj_update_layout(ui->massage_mode);
}


